/*
 * $Id: Textfield.groovy 237 2011-11-14 20:04:40Z andre.winkler@web.de $
 * ============================================================================
 * Project groovy-swinger
 * Copyright (c) 2008-2011 by Andre Winkler. All rights reserved.
 * ============================================================================
 *          GNU LESSER GENERAL PUBLIC LICENSE
 *  TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

package de.awtools.groovy.swinger.builder

import javax.swing.JTextField;

import com.jgoodies.binding.adapter.Bindings;
import com.jgoodies.validation.view.ValidationComponentUtils;

/**
 * Holds the info to build a JTextfield.
 *
 * @author  $Author: andre.winkler@web.de $
 * @version $Revision: 237 $ $Date: 2011-11-14 20:04:40 +0000 (Mon, 14 Nov 2011) $
 */
class Textfield {

    def name
    def columns
    def mandatory
    def editable
    def binding

    String toString() {
        "[Textfield# name: ${name}, columns: ${columns}, mandatory: ${mandatory}, editable: ${editable}, binding: ${binding}]"
    }


    def component() {
        JTextField jtextfield = new JTextField()
        jtextfield.setName(name)
        jtextfield.setColumns(columns)
        jtextfield.setEditable(editable)

        ValidationComponentUtils.setMessageKey(jtextfield, name)
        ValidationComponentUtils.setMandatory(jtextfield, mandatory)
        
        Bindings.bind(jtextfield, gpm.getModel(binding))

        jtextfield
    }

}
